package com.lee.serviceagent.module.employee.controller;

import com.lee.serviceagent.common.constant.ServiceagentSwaggerTagConst;
import com.lee.serviceagent.common.domain.PageResult;
import com.lee.serviceagent.common.domain.ResponseDTO;
import com.lee.serviceagent.common.domain.ValidateList;
import com.lee.serviceagent.module.employee.domain.form.EmployeeAddForm;
import com.lee.serviceagent.module.employee.domain.form.EmployeeQueryForm;
import com.lee.serviceagent.module.employee.domain.form.EmployeeUpdateForm;
import com.lee.serviceagent.module.employee.domain.vo.EmployeeVO;
import com.lee.serviceagent.module.employee.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *   Controller
 *
 * @Author lee
 * @Date 2024-09-12 17:11:30
 * @Copyright lee
 */

@RestController
@Api(tags = {ServiceagentSwaggerTagConst.EMPLOYEE})
@Slf4j
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @ApiOperation("分页查询 @author lee")
    @PostMapping("/employee/queryPage")
    public ResponseDTO<PageResult<EmployeeVO>> queryPage(@RequestBody @Valid EmployeeQueryForm queryForm) {
        log.info("test traceId(Controller)");
        return ResponseDTO.ok(employeeService.queryPage(queryForm));
    }

    @ApiOperation("添加 @author lee")
    @PostMapping("/employee/add")
    public ResponseDTO<String> add(@RequestBody @Valid EmployeeAddForm addForm) {
        return employeeService.add(addForm);
    }

    @ApiOperation("更新 @author lee")
    @PostMapping("/employee/update")
    public ResponseDTO<String> update(@RequestBody @Valid EmployeeUpdateForm updateForm) {
        return employeeService.update(updateForm);
    }

    @ApiOperation("批量删除 @author lee")
    @PostMapping("/employee/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return employeeService.batchDelete(idList);
    }

    @ApiOperation("单个删除 @author lee")
    @GetMapping("/employee/delete/{id}")
    public ResponseDTO<String> batchDelete(@PathVariable Long id) {
        return employeeService.delete(id);
    }



}
